﻿using System;
using System.Linq;
using ActivityFeed.Web.RavenDB;
using OpenWaves.ActivityFeed.RavenDB;
using System.Diagnostics.Contracts;

namespace OpenWaves.ActivityFeed.Web.RavenDB
{
    public class PersonalActivityFeedBuilder : RavenActivityFeedBuilder
    {
        private readonly string subscriberId;

        public PersonalActivityFeedBuilder(string subscriberId, IActivityFeedService activityFeedService, IUpdateDtoBuilder updateDtoBuilder)
            : base(activityFeedService, updateDtoBuilder)
        {
            Contract.Requires<ArgumentNullException>(activityFeedService != null);
            this.subscriberId = subscriberId;
        }

        protected override IQueryable<Update> FilterUpdates(IQueryable<Update> updates)
        {
            Contract.Requires<ArgumentNullException>(updates != null);

            var subscriber = this.ActivityFeedService.GetSubscriber(this.subscriberId);
            return base.FilterUpdates(updates.ForSubscriber(subscriber));
        }
    }
}